<?php

/* *
 * 资讯
 */
namespace Common\Model;
use Think\Model;
class PurchaseMaterialModel extends BaseModel {

    public function queryForList($page=null, $map=null) {
        $list = $this->alias("psm")
            ->join("left join __ADMIN__ emp on emp.employee_id = psm.update_id")
            ->join("left join __CODE__ c on c.code_id = psm.code_id")
            ->join("left join __CODE__ p on p.code_id = c.parentid")
            ->join("left join __MATERIAL__ m on m.code_id = psm.code_id")
            ->where(getWhereSqlByMap($map))
            ->order("psm.purchase_material_id asc")
            ->limit($page->firstRow . ',' . $page->listRows)
            ->field("psm.*, emp.admin_name, c.name as code_name, p.name as parent_name, m.material_name, m.spec, m.prop, m.unit, m.barcode")
            ->select();

        return $list;

    }

    public function getListCount($map = null) {

        $count = $this->alias("psm")
//            ->join("left join __PRODUCT__ p on p.product_id = wo.product_id")
//            ->join("left join __CUSTOMER__ cus on cus.customer_id = wo.customer_id")
            ->where(getWhereSqlByMap($map))
            ->count();

        return $count;
    }

}

